﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TipPanel:UIBase
{
    private Text txtTip;
    //private Button btnSure;
    //public Action Oncomplete;

    private void Start()
    {
        uiType = UIType.TipPanel;
        UIManager.instance.Add(this);
        txtTip = this.transform.Find("txtTip").GetComponent<Text>();
        txtTip.text = "";
        //btnSure = this.transform.Find("btnSure").GetComponent<Button>();
        //btnSure.onClick.AddListener(OnBtnSureClick);
        this.gameObject.SetActive(true);
        HideUI();
    }
    //private void OnBtnSureClick()
    //{
    //    this.gameObject.SetActive(false);
    //    if (Oncomplete!=null)
    //    {
    //        Oncomplete();
    //        Oncomplete = null;
    //    }
    //}

   
    /// <summary>
    /// 这里将委托置为默认空的好处是可变
    /// </summary>
    /// <param name="value"></param>
    /// <param name="action"></param>
    public  void ShowTip(string value,Action action=null)
    {
        this.gameObject.SetActive(true);
        cg.interactable = true;
        cg.alpha = 1;
        txtTip.text = value;
        if (action!=null)
        {
            action.Invoke();
        }
        Invoke("AutoHide", 2.0f);
    }

    void AutoHide()
    {
        cg.interactable = false;
        cg.alpha = 0;
        txtTip.text = string.Empty;
    }

    //private void OnDestroy()
    //{
    //    btnSure.onClick.RemoveAllListeners();
    //}

    //public override void InitUI()
    //{
       
    //    txtTip = this.transform.Find("txtTip").GetComponent<Text>();
    //    txtTip.text = "";
    //    btnSure = this.transform.Find("btnSure").GetComponent<Button>();
    //    btnSure.onClick.AddListener(OnBtnSureClick);

    //    uiType = UIType.TipPanel;
       
    //    this.gameObject.SetActive(false);
    //}

 
   
}
